home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / server / scripts / crossbow.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  25.4 KB  |  942 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Crossbow weapon. This file contains all the items related to this weapon
  8. // including explosions, ammo, the item and the weapon item image.
  9. // These objects rely on the item & inventory support system defined
  10. // in item.cs and inventory.cs
  11. //-----------------------------------------------------------------------------
  12.  
  13. //-----------------------------------------------------------------------------
  14. // Sounds profiles
  15.  
  16. datablock AudioProfile(CrossbowReloadSound)
  17. {
  18. filename = "~/data/sound/crossbow_reload.ogg";
  19. description = AudioClose3d;
  20. preload = true;
  21. };
  22.  
  23. datablock AudioProfile(CrossbowFireSound)
  24. {
  25. filename = "~/data/sound/crossbow_firing.ogg";
  26. description = AudioClose3d;
  27. preload = true;
  28. };
  29.  
  30. datablock AudioProfile(CrossbowFireEmptySound)
  31. {
  32. filename = "~/data/sound/crossbow_firing_empty.ogg";
  33. description = AudioClose3d;
  34. preload = true;
  35. };
  36.  
  37. datablock AudioProfile(CrossbowExplosionSound)
  38. {
  39. filename = "~/data/sound/crossbow_explosion.ogg";
  40. description = AudioDefault3d;
  41. preload = true;
  42. };
  43.  
  44. //-----------------------------------------------------------------------------
  45. // Crossbow bolt projectile splash
  46.  
  47. datablock ParticleData(CrossbowSplashMist)
  48. {
  49.    dragCoefficient      = 2.0;
  50.    gravityCoefficient   = -0.05;
  51.    inheritedVelFactor   = 0.0;
  52.    constantAcceleration = 0.0;
  53.    lifetimeMS           = 400;
  54.    lifetimeVarianceMS   = 100;
  55.    useInvAlpha          = false;
  56.    spinRandomMin        = -90.0;
  57.    spinRandomMax        = 500.0;
  58.    textureName          = "~/data/shapes/crossbow/splash";
  59.    
  60.    colors[0]     = "0.7 0.8 1.0 1.0";
  61.    colors[1]     = "0.7 0.8 1.0 0.5";
  62.    colors[2]     = "0.7 0.8 1.0 0.0";
  63.    
  64.    sizes[0]      = 0.5;
  65.    sizes[1]      = 0.5;
  66.    sizes[2]      = 0.8;
  67.    times[0]      = 0.0;
  68.    times[1]      = 0.5;
  69.    times[2]      = 1.0;
  70. };
  71.  
  72. datablock ParticleEmitterData(CrossbowSplashMistEmitter)
  73. {
  74.    ejectionPeriodMS = 5;
  75.    periodVarianceMS = 0;
  76.    ejectionVelocity = 3.0;
  77.    velocityVariance = 2.0;
  78.    ejectionOffset   = 0.0;
  79.    thetaMin         = 85;
  80.    thetaMax         = 85;
  81.    phiReferenceVel  = 0;
  82.    phiVariance      = 360;
  83.    overrideAdvance = false;
  84.    lifetimeMS       = 250;
  85.    particles = "CrossbowSplashMist";
  86. };
  87.  
  88. datablock ParticleData( CrossbowSplashParticle )
  89. {
  90.    dragCoefficient      = 1;
  91.    gravityCoefficient   = 0.2;
  92.    inheritedVelFactor   = 0.2;
  93.    constantAcceleration = -0.0;
  94.    lifetimeMS           = 600;
  95.    lifetimeVarianceMS   = 0;
  96.    colors[0]     = "0.7 0.8 1.0 1.0";
  97.    colors[1]     = "0.7 0.8 1.0 0.5";
  98.    colors[2]     = "0.7 0.8 1.0 0.0";
  99.    sizes[0]      = 0.5;
  100.    sizes[1]      = 0.5;
  101.    sizes[2]      = 0.5;
  102.    times[0]      = 0.0;
  103.    times[1]      = 0.5;
  104.    times[2]      = 1.0;
  105. };
  106.  
  107. datablock ParticleEmitterData( CrossbowSplashEmitter )
  108. {
  109.    ejectionPeriodMS = 1;
  110.    periodVarianceMS = 0;
  111.    ejectionVelocity = 3;
  112.    velocityVariance = 1.0;
  113.    ejectionOffset   = 0.0;
  114.    thetaMin         = 60;
  115.    thetaMax         = 80;
  116.    phiReferenceVel  = 0;
  117.    phiVariance      = 360;
  118.    overrideAdvance = false;
  119.    orientParticles  = true;
  120.    lifetimeMS       = 100;
  121.    particles = "CrossbowSplashParticle";
  122. };
  123.  
  124. datablock SplashData(CrossbowSplash)
  125. {
  126.    numSegments = 15;
  127.    ejectionFreq = 15;
  128.    ejectionAngle = 40;
  129.    ringLifetime = 0.5;
  130.    lifetimeMS = 300;
  131.    velocity = 4.0;
  132.    startRadius = 0.0;
  133.    acceleration = -3.0;
  134.    texWrap = 5.0;
  135.  
  136.    texture = "~/data/shapes/crossbow/splash";
  137.  
  138.    emitter[0] = CrossbowSplashEmitter;
  139.    emitter[1] = CrossbowSplashMistEmitter;
  140.  
  141.    colors[0] = "0.7 0.8 1.0 0.0";
  142.    colors[1] = "0.7 0.8 1.0 0.3";
  143.    colors[2] = "0.7 0.8 1.0 0.7";
  144.    colors[3] = "0.7 0.8 1.0 0.0";
  145.    times[0] = 0.0;
  146.    times[1] = 0.4;
  147.    times[2] = 0.8;
  148.    times[3] = 1.0;
  149. };
  150.  
  151. //-----------------------------------------------------------------------------
  152. // Crossbow bolt projectile particles
  153.  
  154. datablock ParticleData(CrossbowBoltParticle)
  155. {
  156.    textureName          = "~/data/shapes/particles/smoke";
  157.    dragCoefficient     = 0.0;
  158.    gravityCoefficient   = -0.1;   // rises slowly
  159.    inheritedVelFactor   = 0.0;
  160.    lifetimeMS           = 150;
  161.    lifetimeVarianceMS   = 10;   // ...more or less
  162.    useInvAlpha = false;
  163.    spinRandomMin = -30.0;
  164.    spinRandomMax = 30.0;
  165.  
  166.    colors[0]     = "0.1 0.1 0.1 1.0";
  167.    colors[1]     = "0.1 0.1 0.1 1.0";
  168.    colors[2]     = "0.1 0.1 0.1 0";
  169.  
  170.    sizes[0]      = 0.15;
  171.    sizes[1]      = 0.20;
  172.    sizes[2]      = 0.25;
  173.  
  174.    times[0]      = 0.0;
  175.    times[1]      = 0.3;
  176.    times[2]      = 1.0;
  177. };
  178.  
  179. datablock ParticleData(CrossbowBubbleParticle)
  180. {
  181.    textureName          = "~/data/shapes/particles/bubble";
  182.    dragCoefficient      = 0.0;
  183.    gravityCoefficient   = -0.25;   // rises slowly
  184.    inheritedVelFactor   = 0.0;
  185.    constantAcceleration = 0.0;
  186.    lifetimeMS           = 1500;
  187.    lifetimeVarianceMS   = 600;    // ...more or less
  188.    useInvAlpha          = false;
  189.    spinRandomMin        = -100.0;
  190.    spinRandomMax        = 100.0;
  191.  
  192.    colors[0]     = "0.7 0.8 1.0 0.4";
  193.    colors[1]     = "0.7 0.8 1.0 1.0";
  194.    colors[2]     = "0.7 0.8 1.0 0.0";
  195.  
  196.    sizes[0]      = 0.2;
  197.    sizes[1]      = 0.2;
  198.    sizes[2]      = 0.2;
  199.  
  200.    times[0]      = 0.0;
  201.    times[1]      = 0.5;
  202.    times[2]      = 1.0;
  203. };
  204.  
  205. datablock ParticleEmitterData(CrossbowBoltEmitter)
  206. {
  207.    ejectionPeriodMS = 2;
  208.    periodVarianceMS = 0;
  209.  
  210.    ejectionVelocity = 0.0;
  211.    velocityVariance = 0.10;
  212.  
  213.    thetaMin         = 0.0;
  214.    thetaMax         = 90.0;  
  215.  
  216.    particles = CrossbowBoltParticle;
  217. };
  218.  
  219. datablock ParticleEmitterData(CrossbowBoltBubbleEmitter)
  220. {
  221.    ejectionPeriodMS = 9;
  222.    periodVarianceMS = 0;
  223.  
  224.    ejectionVelocity = 1.0;
  225.    ejectionOffset   = 0.1;
  226.    velocityVariance = 0.5;
  227.  
  228.    thetaMin         = 0.0;
  229.    thetaMax         = 80.0;
  230.  
  231.    phiReferenceVel  = 0;
  232.    phiVariance      = 360;
  233.    overrideAdvances = false;  
  234.  
  235.    particles = CrossbowBubbleParticle;
  236. };
  237.  
  238.  
  239. //-----------------------------------------------------------------------------
  240. // Explosion Debris
  241.  
  242. // Debris "spark" explosion
  243. datablock ParticleData(CrossbowDebrisSpark)
  244. {
  245.    textureName          = "~/data/shapes/particles/fire";
  246.    dragCoefficient      = 0;
  247.    gravityCoefficient   = 0.0;
  248.    windCoefficient      = 0;
  249.    inheritedVelFactor   = 0.5;
  250.    constantAcceleration = 0.0;
  251.    lifetimeMS           = 500;
  252.    lifetimeVarianceMS   = 50;
  253.    spinRandomMin = -90.0;
  254.    spinRandomMax =  90.0;
  255.    useInvAlpha   = false;
  256.  
  257.    colors[0]     = "0.8 0.2 0 1.0";
  258.    colors[1]     = "0.8 0.2 0 1.0";
  259.    colors[2]     = "0 0 0 0.0";
  260.  
  261.    sizes[0]      = 0.2;
  262.    sizes[1]      = 0.3;
  263.    sizes[2]      = 0.1;
  264.  
  265.    times[0]      = 0.0;
  266.    times[1]      = 0.5;
  267.    times[2]      = 1.0;
  268. };
  269.  
  270. datablock ParticleEmitterData(CrossbowDebrisSparkEmitter)
  271. {
  272.    ejectionPeriodMS = 20;
  273.    periodVarianceMS = 0;
  274.    ejectionVelocity = 0.5;
  275.    velocityVariance = 0.25;
  276.    ejectionOffset   = 0.0;
  277.    thetaMin         = 0;
  278.    thetaMax         = 90;
  279.    phiReferenceVel  = 0;
  280.    phiVariance      = 360;
  281.    overrideAdvances = false;
  282.    orientParticles  = false;
  283.    lifetimeMS       = 300;
  284.    particles = "CrossbowDebrisSpark";
  285. };
  286.  
  287. datablock ExplosionData(CrossbowDebrisExplosion)
  288. {
  289.    emitter[0] = CrossbowDebrisSparkEmitter;
  290.  
  291.    // Turned off..
  292.    shakeCamera = false;
  293.    impulseRadius = 0;
  294.    lightStartRadius = 0;
  295.    lightEndRadius = 0;
  296. };
  297.  
  298. // Debris smoke trail
  299. datablock ParticleData(CrossbowDebrisTrail)
  300. {
  301.    textureName          = "~/data/shapes/particles/fire";
  302.    dragCoefficient      = 1;
  303.    gravityCoefficient   = 0;
  304.    inheritedVelFactor   = 0;
  305.    windCoefficient      = 0;
  306.    constantAcceleration = 0;
  307.    lifetimeMS           = 800;
  308.    lifetimeVarianceMS   = 100;
  309.    spinSpeed     = 0;
  310.    spinRandomMin = -90.0;
  311.    spinRandomMax =  90.0;
  312.    useInvAlpha   = true;
  313.  
  314.    colors[0]     = "0.8 0.3 0.0 1.0";
  315.    colors[1]     = "0.1 0.1 0.1 0.7";
  316.    colors[2]     = "0.1 0.1 0.1 0.0";
  317.  
  318.    sizes[0]      = 0.2;
  319.    sizes[1]      = 0.3;
  320.    sizes[2]      = 0.4;
  321.  
  322.    times[0]      = 0.1;
  323.    times[1]      = 0.2;
  324.    times[2]      = 1.0;
  325. };
  326.  
  327. datablock ParticleEmitterData(CrossbowDebrisTrailEmitter)
  328. {
  329.    ejectionPeriodMS = 30;
  330.    periodVarianceMS = 0;
  331.    ejectionVelocity = 0.0;
  332.    velocityVariance = 0.0;
  333.    ejectionOffset   = 0.0;
  334.    thetaMin         = 170;
  335.    thetaMax         = 180;
  336.    phiReferenceVel  = 0;
  337.    phiVariance      = 360;
  338.    //overrideAdvances = false;
  339.    //orientParticles  = true;
  340.    lifetimeMS       = 5000;
  341.    particles = "CrossbowDebrisTrail";
  342. };
  343.  
  344. // Debris object
  345. datablock DebrisData(CrossbowExplosionDebris)
  346. {
  347.    shapeFile = "~/data/shapes/crossbow/debris.dts";
  348.    emitters = "CrossbowDebrisTrailEmitter";
  349.    explosion = CrossbowDebrisExplosion;
  350.    
  351.    elasticity = 0.6;
  352.    friction = 0.5;
  353.    numBounces = 1;
  354.    bounceVariance = 1;
  355.    explodeOnMaxBounce = true;
  356.    staticOnMaxBounce = false;
  357.    snapOnMaxBounce = false;
  358.    minSpinSpeed = 0;
  359.    maxSpinSpeed = 700;
  360.    render2D = false;
  361.    lifetime = 4;
  362.    lifetimeVariance = 0.4;
  363.    velocity = 5;
  364.    velocityVariance = 0.5;
  365.    fade = false;
  366.    useRadiusMass = true;
  367.    baseRadius = 0.3;
  368.    gravModifier = 0.5;
  369.    terminalVelocity = 6;
  370.    ignoreWater = true;
  371. };
  372.  
  373.  
  374. //-----------------------------------------------------------------------------
  375. // Bolt Explosion
  376.  
  377. datablock ParticleData(CrossbowExplosionSmoke)
  378. {
  379.    textureName          = "~/data/shapes/particles/smoke";
  380.    dragCoeffiecient     = 100.0;
  381.    gravityCoefficient   = 0;
  382.    inheritedVelFactor   = 0.25;
  383.    constantAcceleration = -0.30;
  384.    lifetimeMS           = 1200;
  385.    lifetimeVarianceMS   = 300;
  386.    useInvAlpha =  true;
  387.    spinRandomMin = -80.0;
  388.    spinRandomMax =  80.0;
  389.  
  390.    colors[0]     = "0.56 0.36 0.26 1.0";
  391.    colors[1]     = "0.2 0.2 0.2 1.0";
  392.    colors[2]     = "0.0 0.0 0.0 0.0";
  393.  
  394.    sizes[0]      = 4.0;
  395.    sizes[1]      = 2.5;
  396.    sizes[2]      = 1.0;
  397.  
  398.    times[0]      = 0.0;
  399.    times[1]      = 0.5;
  400.    times[2]      = 1.0;
  401. };
  402.  
  403. datablock ParticleData(CrossbowExplosionBubble)
  404. {
  405.    textureName          = "~/data/shapes/particles/bubble";
  406.    dragCoeffiecient     = 0.0;
  407.    gravityCoefficient   = -0.25;
  408.    inheritedVelFactor   = 0.0;
  409.    constantAcceleration = 0.0;
  410.    lifetimeMS           = 1500;
  411.    lifetimeVarianceMS   = 600;
  412.    useInvAlpha          = false;
  413.    spinRandomMin        = -100.0;
  414.    spinRandomMax        =  100.0;
  415.  
  416.    colors[0]     = "0.7 0.8 1.0 0.4";
  417.    colors[1]     = "0.7 0.8 1.0 0.4";
  418.    colors[2]     = "0.7 0.8 1.0 0.0";
  419.  
  420.    sizes[0]      = 0.3;
  421.    sizes[1]      = 0.3;
  422.    sizes[2]      = 0.3;
  423.  
  424.    times[0]      = 0.0;
  425.    times[1]      = 0.5;
  426.    times[2]      = 1.0;
  427. };
  428.  
  429. datablock ParticleEmitterData(CrossbowExplosionSmokeEmitter)
  430. {
  431.    ejectionPeriodMS = 10;
  432.    periodVarianceMS = 0;
  433.    ejectionVelocity = 4;
  434.    velocityVariance = 0.5;
  435.    thetaMin         = 0.0;
  436.    thetaMax         = 180.0;
  437.    lifetimeMS       = 250;
  438.    particles = "CrossbowExplosionSmoke";
  439. };
  440.  
  441. datablock ParticleEmitterData(CrossbowExplosionBubbleEmitter)
  442. {
  443.    ejectionPeriodMS = 9;
  444.    periodVarianceMS = 0;
  445.    ejectionVelocity = 1;
  446.    ejectionOffset   = 0.1;
  447.    velocityVariance = 0.5;
  448.    thetaMin         = 0.0;
  449.    thetaMax         = 80.0;
  450.    phiReferenceVel  = 0;
  451.    phiVariance      = 360;
  452.    overrideAdvances = false;
  453.    particles = "CrossbowExplosionBubble";
  454. };
  455.  
  456. datablock ParticleData(CrossbowExplosionFire)
  457. {
  458.    textureName          = "~/data/shapes/particles/fire";
  459.    dragCoeffiecient     = 100.0;
  460.    gravityCoefficient   = 0;
  461.    inheritedVelFactor   = 0.25;
  462.    constantAcceleration = 0.1;
  463.    lifetimeMS           = 1200;
  464.    lifetimeVarianceMS   = 300;
  465.    useInvAlpha =  false;
  466.    spinRandomMin = -80.0;
  467.    spinRandomMax =  80.0;
  468.  
  469.    colors[0]     = "0.8 0.4 0 0.8";
  470.    colors[1]     = "0.2 0.0 0 0.8";
  471.    colors[2]     = "0.0 0.0 0.0 0.0";
  472.  
  473.    sizes[0]      = 1.5;
  474.    sizes[1]      = 0.9;
  475.    sizes[2]      = 0.5;
  476.  
  477.    times[0]      = 0.0;
  478.    times[1]      = 0.5;
  479.    times[2]      = 1.0;
  480. };
  481.  
  482. datablock ParticleEmitterData(CrossbowExplosionFireEmitter)
  483. {
  484.    ejectionPeriodMS = 10;
  485.    periodVarianceMS = 0;
  486.    ejectionVelocity = 0.8;
  487.    velocityVariance = 0.5;
  488.    thetaMin         = 0.0;
  489.    thetaMax         = 180.0;
  490.    lifetimeMS       = 250;
  491.    particles = "CrossbowExplosionFire";
  492. };
  493.  
  494. datablock ParticleData(CrossbowExplosionSparks)
  495. {
  496.    textureName          = "~/data/shapes/particles/spark";
  497.    dragCoefficient      = 1;
  498.    gravityCoefficient   = 0.0;
  499.    inheritedVelFactor   = 0.2;
  500.    constantAcceleration = 0.0;
  501.    lifetimeMS           = 500;
  502.    lifetimeVarianceMS   = 350;
  503.  
  504.    colors[0]     = "0.60 0.40 0.30 1.0";
  505.    colors[1]     = "0.60 0.40 0.30 1.0";
  506.    colors[2]     = "1.0 0.40 0.30 0.0";
  507.  
  508.    sizes[0]      = 0.25;
  509.    sizes[1]      = 0.15;
  510.    sizes[2]      = 0.15;
  511.  
  512.    times[0]      = 0.0;
  513.    times[1]      = 0.5;
  514.    times[2]      = 1.0;
  515. };
  516.  
  517. datablock ParticleData(CrossbowExplosionWaterSparks)
  518. {
  519.    textureName          = "~/data/shapes/particles/bubble";
  520.    dragCoefficient      = 0;
  521.    gravityCoefficient   = 0.0;
  522.    inheritedVelFactor   = 0.2;
  523.    constantAcceleration = 0.0;
  524.    lifetimeMS           = 500;
  525.    lifetimeVarianceMS   = 350;
  526.  
  527.    colors[0]     = "0.4 0.4 1.0 1.0";
  528.    colors[1]     = "0.4 0.4 1.0 1.0";
  529.    colors[2]     = "0.4 0.4 1.0 0.0";
  530.  
  531.    sizes[0]      = 0.5;
  532.    sizes[1]      = 0.5;
  533.    sizes[2]      = 0.5;
  534.  
  535.    times[0]      = 0.0;
  536.    times[1]      = 0.5;
  537.    times[2]      = 1.0;
  538. };
  539.  
  540. datablock ParticleEmitterData(CrossbowExplosionSparkEmitter)
  541. {
  542.    ejectionPeriodMS = 3;
  543.    periodVarianceMS = 0;
  544.    ejectionVelocity = 5;
  545.    velocityVariance = 1;
  546.    ejectionOffset   = 0.0;
  547.    thetaMin         = 0;
  548.    thetaMax         = 180;
  549.    phiReferenceVel  = 0;
  550.    phiVariance      = 360;
  551.    overrideAdvances = false;
  552.    orientParticles  = true;
  553.    lifetimeMS       = 100;
  554.    particles = "CrossbowExplosionSparks";
  555. };
  556.  
  557. datablock ParticleEmitterData(CrossbowExplosionWaterSparkEmitter)
  558. {
  559.    ejectionPeriodMS = 3;
  560.    periodVarianceMS = 0;
  561.    ejectionVelocity = 4;
  562.    velocityVariance = 4;
  563.    ejectionOffset   = 0.0;
  564.    thetaMin         = 0;
  565.    thetaMax         = 60;
  566.    phiReferenceVel  = 0;
  567.    phiVariance      = 360;
  568.    overrideAdvances = false;
  569.    orientParticles  = true;
  570.    lifetimeMS       = 200;
  571.    particles = "CrossbowExplosionWaterSparks";
  572. };
  573.  
  574. datablock ExplosionData(CrossbowSubExplosion1)
  575. {
  576.    offset = 0;
  577.    emitter[0] = CrossbowExplosionSmokeEmitter;
  578.    emitter[1] = CrossbowExplosionSparkEmitter;
  579. };
  580.  
  581. datablock ExplosionData(CrossbowSubExplosion2)
  582. {
  583.    offset = 1.0;
  584.    emitter[0] = CrossbowExplosionSmokeEmitter;
  585.    emitter[1] = CrossbowExplosionSparkEmitter;
  586. };
  587.  
  588. datablock ExplosionData(CrossbowSubWaterExplosion1)
  589. {
  590.    delayMS   = 100;
  591.    offset    = 1.2;
  592.    playSpeed = 1.5;
  593.  
  594.    emitter[0] = CrossbowExplosionBubbleEmitter;
  595.    emitter[1] = CrossbowExplosionWaterSparkEmitter;
  596.    
  597.    sizes[0] = "0.75 0.75 0.75";
  598.    sizes[1] = "1.0 1.0 1.0";
  599.    sizes[2] = "0.5 0.5 0.5";
  600.    times[0] = 0.0;
  601.    times[1] = 0.5;
  602.    times[2] = 1.0;
  603. };
  604.  
  605. datablock ExplosionData(CrossbowSubWaterExplosion2)
  606. {
  607.    delayMS   = 50;
  608.    offset    = 1.2;
  609.    playSpeed = 0.75;
  610.  
  611.    emitter[0] = CrossbowExplosionBubbleEmitter;
  612.    emitter[1] = CrossbowExplosionWaterSparkEmitter;
  613.  
  614.    sizes[0] = "1.5 1.5 1.5";
  615.    sizes[1] = "1.5 1.5 1.5";
  616.    sizes[2] = "1.0 1.0 1.0";
  617.    times[0] = 0.0;
  618.    times[1] = 0.5;
  619.    times[2] = 1.0;
  620. };
  621.  
  622. datablock ExplosionData(CrossbowExplosion)
  623. {
  624.    soundProfile = CrossbowExplosionSound;
  625.    lifeTimeMS = 1200;
  626.  
  627.    // Volume particles
  628.    particleEmitter = CrossbowExplosionFireEmitter;
  629.    particleDensity = 75;
  630.    particleRadius = 2;
  631.  
  632.    // Point emission
  633.    emitter[0] = CrossbowExplosionSmokeEmitter;
  634.    emitter[1] = CrossbowExplosionSparkEmitter;
  635.  
  636.    // Sub explosion objects
  637.    subExplosion[0] = CrossbowSubExplosion1;
  638.    subExplosion[1] = CrossbowSubExplosion2;
  639.    
  640.    // Camera Shaking
  641.    shakeCamera = true;
  642.    camShakeFreq = "10.0 11.0 10.0";
  643.    camShakeAmp = "1.0 1.0 1.0";
  644.    camShakeDuration = 0.5;
  645.    camShakeRadius = 10.0;
  646.  
  647.    // Exploding debris
  648.    debris = CrossbowExplosionDebris;
  649.    debrisThetaMin = 0;
  650.    debrisThetaMax = 60;
  651.    debrisPhiMin = 0;
  652.    debrisPhiMax = 360;
  653.    debrisNum = 6;
  654.    debrisNumVariance = 2;
  655.    debrisVelocity = 1;
  656.    debrisVelocityVariance = 0.5;
  657.    
  658.    // Impulse
  659.    impulseRadius = 10;
  660.    impulseForce = 15;
  661.  
  662.    // Dynamic light
  663.    lightStartRadius = 6;
  664.    lightEndRadius = 3;
  665.    lightStartColor = "0.5 0.5 0";
  666.    lightEndColor = "0 0 0";
  667. };
  668.  
  669. datablock ExplosionData(CrossbowWaterExplosion)
  670. {
  671.    soundProfile = CrossbowExplosionSound;
  672.  
  673.    // Volume particles
  674.    particleEmitter = CrossbowExplosionBubbleEmitter;
  675.    particleDensity = 375;
  676.    particleRadius = 2;
  677.  
  678.  
  679.    // Point emission
  680.    emitter[0] = CrossbowExplosionBubbleEmitter;
  681.    emitter[1] = CrossbowExplosionWaterSparkEmitter;
  682.  
  683.    // Sub explosion objects
  684.    subExplosion[0] = CrossbowSubWaterExplosion1;
  685.    subExplosion[1] = CrossbowSubWaterExplosion2;
  686.    
  687.    // Camera Shaking
  688.    shakeCamera = true;
  689.    camShakeFreq = "8.0 9.0 7.0";
  690.    camShakeAmp = "3.0 3.0 3.0";
  691.    camShakeDuration = 1.3;
  692.    camShakeRadius = 20.0;
  693.  
  694.    // Exploding debris
  695.    debris = CrossbowExplosionDebris;
  696.    debrisThetaMin = 0;
  697.    debrisThetaMax = 60;
  698.    debrisPhiMin = 0;
  699.    debrisPhiMax = 360;
  700.    debrisNum = 6;
  701.    debrisNumVariance = 2;
  702.    debrisVelocity = 0.5;
  703.    debrisVelocityVariance = 0.2;
  704.    
  705.    // Impulse
  706.    impulseRadius = 10;
  707.    impulseForce = 15;
  708.  
  709.    // Dynamic light
  710.    lightStartRadius = 6;
  711.    lightEndRadius = 3;
  712.    lightStartColor = "0 0.5 0.5";
  713.    lightEndColor = "0 0 0";
  714. };
  715.  
  716. //-----------------------------------------------------------------------------
  717. // Projectile Object
  718.  
  719. datablock ProjectileData(CrossbowProjectile)
  720. {
  721.    projectileShapeName = "~/data/shapes/crossbow/projectile.dts";
  722.    directDamage        = 20;
  723.    radiusDamage        = 20;
  724.    damageRadius        = 1.5;
  725.    areaImpulse         = 200;
  726.  
  727.    explosion           = CrossbowExplosion;
  728.    waterExplosion      = CrossbowWaterExplosion;
  729.  
  730.    particleEmitter     = CrossbowBoltEmitter;
  731.    particleWaterEmitter= CrossbowBoltBubbleEmitter;
  732.  
  733.    splash              = CrossbowSplash;
  734.  
  735.    muzzleVelocity      = 100;
  736.    velInheritFactor    = 0.3;
  737.  
  738.    armingDelay         = 0;
  739.    lifetime            = 5000;
  740.    fadeDelay           = 5000;
  741.    bounceElasticity    = 0;
  742.    bounceFriction      = 0;
  743.    isBallistic         = false;
  744.    gravityMod = 0.80;
  745.  
  746.    hasLight    = true;
  747.    lightRadius = 4;
  748.    lightColor  = "0.5 0.5 0.25";
  749.  
  750.    hasWaterLight     = true;
  751.    waterLightColor   = "0 0.5 0.5";
  752. };
  753.  
  754. function CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
  755. {
  756.    // Apply damage to the object all shape base objects
  757.    if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
  758.       %col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");
  759.  
  760.    // Radius damage is a support scripts defined in radiusDamage.cs
  761.    // Push the contact point away from the contact surface slightly
  762.    // along the contact normal to derive the explosion center. -dbs
  763.    radiusDamage(%obj, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
  764. }
  765.  
  766.  
  767. //-----------------------------------------------------------------------------
  768. // Ammo Item
  769.  
  770. datablock ItemData(CrossbowAmmo)
  771. {
  772.    // Mission editor category
  773.    category = "Ammo";
  774.  
  775.    // Add the Ammo namespace as a parent.  The ammo namespace provides
  776.    // common ammo related functions and hooks into the inventory system.
  777.    className = "Ammo";
  778.  
  779.    // Basic Item properties
  780.    shapeFile = "~/data/shapes/crossbow/ammo.dts";
  781.    mass = 1;
  782.    elasticity = 0.2;
  783.    friction = 0.6;
  784.  
  785.    // Dynamic properties defined by the scripts
  786.    pickUpName = "crossbow bolts";
  787.    maxInventory = 20;
  788. };
  789.  
  790.  
  791. //--------------------------------------------------------------------------
  792. // Weapon Item.  This is the item that exists in the world, i.e. when it's
  793. // been dropped, thrown or is acting as re-spawnable item.  When the weapon
  794. // is mounted onto a shape, the CrossbowImage is used.
  795.  
  796. datablock ItemData(Crossbow)
  797. {
  798.    // Mission editor category
  799.    category = "Weapon";
  800.  
  801.    // Hook into Item Weapon class hierarchy. The weapon namespace
  802.    // provides common weapon handling functions in addition to hooks
  803.    // into the inventory system.
  804.    className = "Weapon";
  805.  
  806.    // Basic Item properties
  807.    shapeFile = "~/data/shapes/crossbow/weapon.dts";
  808.    mass = 1;
  809.    elasticity = 0.2;
  810.    friction = 0.6;
  811.    emap = true;
  812.  
  813.     // Dynamic properties defined by the scripts
  814.     pickUpName = "a crossbow";
  815.     image = CrossbowImage;
  816. };
  817.  
  818.  
  819. //--------------------------------------------------------------------------
  820. // Crossbow image which does all the work.  Images do not normally exist in
  821. // the world, they can only be mounted on ShapeBase objects.
  822.  
  823. datablock ShapeBaseImageData(CrossbowImage)
  824. {
  825.    // Basic Item properties
  826.    shapeFile = "~/data/shapes/crossbow/weapon.dts";
  827.    emap = true;
  828.  
  829.    // Specify mount point & offset for 3rd person, and eye offset
  830.    // for first person rendering.
  831.    mountPoint = 0;
  832.    eyeOffset = "0.1 0.4 -0.6";
  833.  
  834.    // When firing from a point offset from the eye, muzzle correction
  835.    // will adjust the muzzle vector to point to the eye LOS point.
  836.    // Since this weapon doesn't actually fire from the muzzle point,
  837.    // we need to turn this off.  
  838.    correctMuzzleVector = false;
  839.  
  840.    // Add the WeaponImage namespace as a parent, WeaponImage namespace
  841.    // provides some hooks into the inventory system.
  842.    className = "WeaponImage";
  843.  
  844.    // Projectile && Ammo.
  845.    item = Crossbow;
  846.    ammo = CrossbowAmmo;
  847.    projectile = CrossbowProjectile;
  848.    projectileType = Projectile;
  849.  
  850.    // Images have a state system which controls how the animations
  851.    // are run, which sounds are played, script callbacks, etc. This
  852.    // state system is downloaded to the client so that clients can
  853.    // predict state changes and animate accordingly.  The following
  854.    // system supports basic ready->fire->reload transitions as
  855.    // well as a no-ammo->dryfire idle state.
  856.  
  857.    // Initial start up state
  858.    stateName[0]                     = "Preactivate";
  859.    stateTransitionOnLoaded[0]       = "Activate";
  860.    stateTransitionOnNoAmmo[0]       = "NoAmmo";
  861.  
  862.    // Activating the gun.  Called when the weapon is first
  863.    // mounted and there is ammo.
  864.    stateName[1]                     = "Activate";
  865.    stateTransitionOnTimeout[1]      = "Ready";
  866.    stateTimeoutValue[1]             = 0.6;
  867.    stateSequence[1]                 = "Activate";
  868.  
  869.    // Ready to fire, just waiting for the trigger
  870.    stateName[2]                     = "Ready";
  871.    stateTransitionOnNoAmmo[2]       = "NoAmmo";
  872.    stateTransitionOnTriggerDown[2]  = "Fire";
  873.  
  874.    // Fire the weapon. Calls the fire script which does 
  875.    // the actual work.
  876.    stateName[3]                     = "Fire";
  877.    stateTransitionOnTimeout[3]      = "Reload";
  878.    stateTimeoutValue[3]             = 0.2;
  879.    stateFire[3]                     = true;
  880.    stateRecoil[3]                   = LightRecoil;
  881.    stateAllowImageChange[3]         = false;
  882.    stateSequence[3]                 = "Fire";
  883.    stateScript[3]                   = "onFire";
  884.    stateSound[3]                    = CrossbowFireSound;
  885.  
  886.    // Play the relead animation, and transition into
  887.    stateName[4]                     = "Reload";
  888.    stateTransitionOnNoAmmo[4]       = "NoAmmo";
  889.    stateTransitionOnTimeout[4]      = "Ready";
  890.    stateTimeoutValue[4]             = 0.8;
  891.    stateAllowImageChange[4]         = false;
  892.    stateSequence[4]                 = "Reload";
  893.    stateEjectShell[4]               = true;
  894.    stateSound[4]                    = CrossbowReloadSound;
  895.  
  896.    // No ammo in the weapon, just idle until something
  897.    // shows up. Play the dry fire sound if the trigger is
  898.    // pulled.
  899.    stateName[5]                     = "NoAmmo";
  900.    stateTransitionOnAmmo[5]         = "Reload";
  901.    stateSequence[5]                 = "NoAmmo";
  902.    stateTransitionOnTriggerDown[5]  = "DryFire";
  903.  
  904.    // No ammo dry fire
  905.    stateName[6]                     = "DryFire";
  906.    stateTimeoutValue[6]             = 1.0;
  907.    stateTransitionOnTimeout[6]      = "NoAmmo";
  908.    stateSound[6]                    = CrossbowFireEmptySound;
  909. };
  910.  
  911.  
  912. //-----------------------------------------------------------------------------
  913.  
  914. function CrossbowImage::onFire(%this, %obj, %slot)
  915. {
  916.    %projectile = %this.projectile;
  917.  
  918.    // Decrement inventory ammo. The image's ammo state is update
  919.    // automatically by the ammo inventory hooks.
  920.    %obj.decInventory(%this.ammo,1);
  921.  
  922.    // Determin initial projectile velocity based on the 
  923.    // gun's muzzle point and the object's current velocity
  924.    %muzzleVector = %obj.getMuzzleVector(%slot);
  925.    %objectVelocity = %obj.getVelocity();
  926.    %muzzleVelocity = VectorAdd(
  927.       VectorScale(%muzzleVector, %projectile.muzzleVelocity),
  928.       VectorScale(%objectVelocity, %projectile.velInheritFactor));
  929.  
  930.    // Create the projectile object
  931.    %p = new (%this.projectileType)() {
  932.       dataBlock        = %projectile;
  933.       initialVelocity  = %muzzleVelocity;
  934.       initialPosition  = %obj.getMuzzlePoint(%slot);
  935.       sourceObject     = %obj;
  936.       sourceSlot       = %slot;
  937.       client           = %obj.client;
  938.    };
  939.    MissionCleanup.add(%p);
  940.    return %p;
  941. }
  942.